package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	
	public class keyCodes extends Sprite
	{
		private var role:Sprite;
		private var speed:int = 5;
		private var keyObj:Object = {};
		private var keyArr:Array = [];
		
		public function keyCodes():void
		{
			role=new Sprite();
			role.graphics.beginFill(0xff00ff);
			role.graphics.drawRect(10,-40,20,40);
			role.graphics.endFill();
			role.x = 150;
			role.y = 200;
			addChild(role);
			stage.focus = this;
			keyOne();
		}
		
		private function keyOne():void
		{
			stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyDownHandler);
			stage.addEventListener(KeyboardEvent.KEY_UP,KeyUpHandler);
		}
		
		private function KeyDownHandler(e:KeyboardEvent):void
		{
			keyObj[e.keyCode] = true;
			
			if (keyObj[SPACE])
			{
				trace("space");
			}
			if (keyObj[LEFT] || keyObj[A])
			{
				trace("left");
				role.x -=  speed;
			}
			if (keyObj[DOWN] || keyObj[S])
			{
				trace("down");
				role.y +=  speed;
			}
			if (keyObj[RIGHT] || keyObj[D])
			{
				trace("right");
				role.x +=  speed;
			}
			if (keyObj[UP] || keyObj[W])
			{
				trace("up");
				role.y -=  speed;
			}
			if (keyObj[CONTROL] && keyObj[ENTER])
			{
				trace("control + enter");
				var txt:TextField=new TextField();
				txt.multiline = true;
				txt.wordWrap = true;
				txt.text = "control + enter";
				txt.x=int(50*Math.random());
				txt.y=-int(200*Math.random());
				while(role.numChildren>0)
				{
					role.removeChildAt(0);
				}
				role.addChild(txt);
			}
		}
		
		private function KeyUpHandler(e:KeyboardEvent):void
		{
			keyObj[e.keyCode] = false;
		}
		
		private function keyTwo():void
		{
			stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
			stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);
			addEventListener(Event.ENTER_FRAME,enterFrameHandler);
		}
		
		private function keyDownHandler(e:KeyboardEvent):void
		{
			var num:int = keyArr.indexOf(e.keyCode);
			if (num<0)
			{
				keyArr.push(e.keyCode);
			}
		}
		
		private function keyUpHandler(e:KeyboardEvent):void
		{
			var num:int = keyArr.indexOf(e.keyCode);
			if (num>=0)
			{
				keyArr.splice(num,1);
			}
			
		}
		
		private function enterFrameHandler(e:Event):void
		{
			trace(keyArr);
		}
		
		//STATIC
		static public var A:int = 65;
		static public var B:int = 66;
		static public var C:int = 67;
		static public var D:int = 68;
		static public var E:int = 69;
		static public var F:int = 70;
		static public var G:int = 71;
		static public var H:int = 72;
		static public var I:int = 73;
		static public var J:int = 74;
		static public var K:int = 75;
		static public var L:int = 76;
		static public var M:int = 77;
		static public var N:int = 78;
		static public var O:int = 79;
		static public var P:int = 80;
		static public var Q:int = 81;
		static public var R:int = 82;
		static public var S:int = 83;
		static public var T:int = 84;
		static public var U:int = 85;
		static public var V:int = 86;
		static public var W:int = 87;
		static public var X:int = 88;
		static public var Y:int = 89;
		static public var Z:int = 90;
		//
		static public var NUMBER_0:int = 48;
		static public var NUMBER_1:int = 49;
		static public var NUMBER_2:int = 50;
		static public var NUMBER_3:int = 51;
		static public var NUMBER_4:int = 52;
		static public var NUMBER_5:int = 53;
		static public var NUMBER_6:int = 54;
		static public var NUMBER_7:int = 55;
		static public var NUMBER_8:int = 56;
		static public var NUMBER_9:int = 57;
		//
		static public var SHIFT:int = 16;
		static public var CONTROL:int = 17;
		static public var SPACE:int = 32;
		static public var ENTER:int = 13;
		static public var TAB:int = 9;
		//
		static public var LEFT:int = 37;
		static public var UP:int = 38;
		static public var RIGHT:int = 39;
		static public var DOWN:int = 40;
	}
}
/*package { 
	import flash.display.Sprite; 
	import flash.ui.Keyboard; 
	import flash.events.KeyboardEvent; 
	
	public class keyCodes extends Sprite 
	{ 
		
		public function keyCodes() 
		{ 
			init(); 
		} 
		
		private function init():void
		{ 
			var ball:Sprite = new Sprite(); 
			addChild(ball); 
			ball.graphics.beginFill(0xFFFF00); 
			ball.graphics.drawCircle(0,0,100); 
			ball.graphics.endFill(); 
			ball.x = stage.stageWidth/2; 
			ball.y = stage.stageHeight/2; 
			stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyboardEvent); 
			function onKeyboardEvent(e:KeyboardEvent)
			{ 
				switch(e.keyCode){ 
					case Keyboard.UP: 
						ball.y -= 10; 
						break; 
					case Keyboard.DOWN: 
						ball.y += 10; 
						break; 
					case Keyboard.LEFT: 
						ball.x -= 10; 
						break; 
					case Keyboard.RIGHT: 
						ball.x += 10; 
						break; 
					
					default: 
						break; 
				} 
			} 
		} 
	} 
} */